﻿using Architecture.API.Application.Command.RequestForLeaveCommand;
using Architecture.Domain.Service.LeaveServices;
using MediatR;

namespace Architecture.API.Application.CommandHandlers.RequestForLeaveHandler
{
    /// <summary>
    /// 
    /// </summary>
    public class LeaveCreateCommandHandler : IRequestHandler<LeaveCreateCommand, int>
    {
        /// <summary>
        /// 请假服务
        /// </summary>
        protected readonly ILeaveService _leaveService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="leaveService">请假服务</param>
        public LeaveCreateCommandHandler(ILeaveService leaveService)
        {
            _leaveService = leaveService;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回受影响的行数</returns>
        public async Task<int> Handle(LeaveCreateCommand request, CancellationToken cancellationToken)
        {
            return await _leaveService.AddLeave(new Domain.RequestForLeave() { UserName=request.UserName,DepartmentId=request.DepartmentId,LeaveType=request.LeaveType,LeaveStartTime=request.LeaveStartTime, LeaveEndTime = request.LeaveEndTime, TotalWorkTime=request.TotalWorkTime,RegistrationTime=request.RegistrationTime,SubjectMatter=request.SubjectMatter,DepartmentLeader=request.DepartmentLeader});
        }
    }
}
